import tensorflow as tf

x = tf.random.normal([2, 5])
w = tf.random.normal([5, 3])
b = tf.zeros([3])
y = tf.constant([2, 0])

with tf.GradientTape() as tape:
    tape.watch([w, b])
    probability = tf.nn.softmax(x @ w + b, axis=1)
    loss = tf.reduce_mean(tf.losses.MSE(tf.one_hot(y, depth=3), probability))
gradient = tape.gradient(loss, [w, b])

print(probability)
print(gradient)
